package com.shangma.cn.service.base.impl;

import com.shangma.cn.commons.utils.ReflectionUtils;
import com.shangma.cn.mapper.base.MyMapper;
import com.shangma.cn.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 开发人员: 辉哥真球帅
 * 联系方式: zhengzhoudaxuevip@163.com
 * 创建时间: 2021/10/8  11:34
 * 文件含义:
 */
public class BaseServiceImpl<T> implements BaseService<T> {


    @Autowired
    private MyMapper<T> myMapper;

    @Override
    public List<T> list() {
        return myMapper.selectList(null);
    }

    @Override
    public T findOne(Long id) {
        return myMapper.selectById(id);
    }

    @Override
    public List<T> findBatchByIds(List<Long> ids) {
        return myMapper.selectBatchIds(ids);
    }

    @Override
    public int addEntity(T t) {
        ReflectionUtils.invokeMethod(t, "setData", null, null);
        return myMapper.insert(t);
    }

    @Override
    public int deleteByIds(List<Long> ids) {
        return myMapper.deleteBatchIds(ids);
    }

    @Override
    public int deleteById(Long id) {
        return myMapper.deleteById(id);
    }

    @Override
    public int updateEntity(T t) {
        ReflectionUtils.invokeMethod(t, "setData", null, null);
        return myMapper.updateById(t);
    }
}
